<?php
/**
 *
 * @author dinglin
 * 打卡日志表 access_day_record
 */
class Oa_Data_AccessDayRecord{

    //所有可能用户打卡状态基准数据
    private function access_day_record(){
        $fields = array('access_date','start_work','end_work','user_id');
        $values =
        array(
                array(0,'0900','1800',0),//正常

                array(0,'0910','0910',0),//下午缺勤
                array(0,'0910','0911',0),//下午缺勤
                array(0,'0910','0931',0),//下午缺勤
                array(0,'0910','1401',0),//下午缺勤
                array(0,'0910','1411',0),//下午缺勤
                array(0,'0910','1431',0),//下午缺勤
                array(0,'0910','1730',0),//早退
                array(0,'0910','1800',0),//正常

                array(0,'0911','0912',0),//迟到,下午缺勤
                array(0,'0911','0931',0),//迟到,下午缺勤
                array(0,'0911','1401',0),//迟到,下午缺勤
                array(0,'0911','1411',0),//迟到,下午缺勤
                array(0,'0911','1431',0),//迟到,下午缺勤
                array(0,'0911','1730',0),//迟到,早退
                array(0,'0911','1830',0),//迟到,下午缺勤

                array(0,'0931','0931',0),//全天缺勤
                array(0,'0931','1401',0),//全天缺勤
                array(0,'0931','1411',0),//全天缺勤
                array(0,'0931','1431',0),//全天缺勤
                array(0,'0931','1730',0),//上午缺勤,早退
                array(0,'0931','1800',0),//上午缺勤

                array(0,'1401','1401',0),//全天缺勤
                array(0,'1401','1411',0),//全天缺勤
                array(0,'1401','1431',0),//全天缺勤
                array(0,'1401','1730',0),//上午缺勤,早退
                array(0,'1401','1800',0),//上午缺勤

                array(0,'1411','1411',0),//全天缺勤
                array(0,'1411','1431',0),//全天缺勤
                array(0,'1411','1730',0),//上午缺勤,早退
                array(0,'1411','1800',0),//上午缺勤

                array(0,'1431','1431',0),//全天缺勤
                array(0,'1431','1730',0),//上午缺勤,早退
                array(0,'1431','1800',0),//上午缺勤

                array(0,'1800','1800',0),//全天缺勤
        );
        //数据组合
        $result = array();
        foreach($values as $key => $value){
            foreach ($fields as $k => $f){
                $result[$key][$f] = $value[$k];
            }
        }
        return $result;
    }
    /**
     * 根据user_id 可能打卡状态
     * $start = Ymd
     * $end   = Ymd
     * 返回多组测试数据
     */
   public static function get_user_day_records($user_id,$start='',$end=''){
       $all_record = $this->access_day_record();
       $count = count($all_record);
       if(!start && !$end){
           $end = date('Ymd');
           $start = date('Ymd',time() - $count *24 *60*60);
       }
       $days = (strtotime($end)-strtotime($start))/(24*60*60);
       $groups = $count/$days;
       if( $count % $days != 0 ){
           $groups++;
       }
       $result = array();
       $group = 0;
       $_start = $start;
       foreach ($all_record as $key=>$value){
           if( $_start == $end ){
               $group++;
               $_start = $start;
           }
           $result[$group][$key]=$value;
           $result[$group][$key]['access_date'] = $_start;
           $result[$group][$key]['user_id']     = $user_id;
           $_start = date('Ymd',strtotime($_start)+24*60*60);
       }
       return $result;
   }
   /**
    * 获取某日的多user_ids个用户的打卡记录
    */
   public static function get_users_day_records($user_ids,$date){
   }
}